<!--- ========================================================================== --->
<!--- Group Approval Route and Data Flow                                         --->
<!--- by Maan 12072007 (part of Group Approval eTask application)                --->
<!--- ========================================================================== --->

<CFIF isDefined("form.btnUpdateFF")>
	<CFIF isDefined("form.selActivity")>
		<CFINCLUDE TEMPLATE="batchAppFlow.cfm">
	</CFIF>
<CFELSEIF isDefined("form.btnRouteForms")><!--- routing --->
	<CFIF NOT isDefined("url.returned")>
		<!--- get employees --->
		<CFQUERY NAME="qryBatchEmps" DATASOURCE="#client.company_dsn#">
			SELECT A.* FROM ECINBATCHEMPS A, ECRGBATCHAPPLY B
			WHERE 	(A.BATCHID = B.BATCHID) AND
				(A.BATCHID = '#getform.formcode#') AND
				(A.DOCNUMBER = '#url.docnumber#')
		</CFQUERY>
		<!--- get distinct records --->
		<CFQUERY NAME="qryRefID" DATASOURCE="#client.company_dsn#">
			SELECT DISTINCT(A.REFERENCEID), A.PERSONNELIDNO FROM ECINBATCHDTL A, ECINBATCHEMPS B
			WHERE 	(A.BATCHID = B.BATCHID) AND
				(A.BATCHID = '#getform.formcode#') AND
				(A.DOCNUMBER = B.DOCNUMBER) AND	
				(A.DOCNUMBER = '#url.docnumber#') AND
				(A.PERSONNELIDNO = B.PERSONNELIDNO)
		</CFQUERY>
		<!--- check routing and selected destinations --->
		<CFQUERY NAME="qryBatchProcess" DATASOURCE="#client.company_dsn#">
			SELECT A.* FROM ECINBATCHROUTEROLE A, ECINBATCHAPPLY B
			WHERE 	(A.BATCHID = B.BATCHID) AND
				(A.DOCNUMBER = B.DOCNUMBER) AND
				(A.BATCHID = '#getform.formcode#') AND
				(A.DOCNUMBER = '#url.docnumber#')
		</CFQUERY>
		<CFIF qryRefID.RECORDCOUNT>
			<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLevel.LEVELID#">
			<CFSET sFields = QuotedValueList(GetLevel.COLUMNNAME)>
			<CFQUERY NAME="autogen" DATASOURCE="#client.global_dsn#">
				SELECT * FROM GSTAUTOGENFIELD
				WHERE TABLENAME ='#GetData.TABLENAME_FK#' AND FIELDNAME IN (#preserveSingleQuotes(sFields)#)
			</CFQUERY>
			<CFLOOP QUERY = "qryRefID">
				<CFSET sValues = "">
				<CFSET sFields = "">
				<CFSET isFirst = "Y">
				<!--- get equivalent record --->
				<CFQUERY NAME="qryBatchDtl" DATASOURCE="#client.company_dsn#">
					SELECT A.* FROM ECINBATCHDTL A, ECINBATCHEMPS B
					WHERE 	(A.BATCHID = B.BATCHID) AND
						(A.BATCHID = '#getform.formcode#') AND
						(A.DOCNUMBER = B.DOCNUMBER) AND	
						(A.DOCNUMBER = '#url.docnumber#') AND
						(A.PERSONNELIDNO = B.PERSONNELIDNO) AND
						(A.PERSONNELIDNO = '#PERSONNELIDNO#') AND 
						(A.REFERENCEID = '#REFERENCEID#')
				</CFQUERY>
				<!--- assign routeid --->
				<CFSET sRouteid = CreateUUID()>
				<CFIF qryBatchDtl.RECORDCOUNT> <!--- proceed to routing ONLY if there is an existing record -- maan 01/02/2008 --->
				<!--- insert to respective tables --->
					<CFLOOP QUERY="qryBatchDtl">
						<CFIF autogen.RECORDCOUNT NEQ 0 AND autogen.FIELDNAME EQ COLUMNNAME><!--- autogenfield --->
							<CFMODULE TEMPLATE="#client.common_path#autogenfield.cfm"
								SEEDKEY="#autogen.SEEDKEY#"
								CODELENGTH="#autogen.CODELENGTH#"
								COLUMNNAME="#COLUMNNAME#"
								TABLENAME_FK="#GetData.TABLENAME_FK#"
								DATASOURCE="#DSN#"
								WITHDATE="#autogen.WITHDATE#"
								SOURCETABLE="#GetData.TABLENAME_FK#">
							<CFSET sVal = AUTOGENVALUE>
						<CFELSEIF COLUMNNAME NEQ "APPROVED" AND COLUMNNAME NEQ "ROUTEID">
							<CFSET sVal = FIELDVALUE>
						</CFIF>
						<CFIF isFirst EQ "Y">
							<CFSET sFields = COLUMNNAME>
							<CFSET sValues = "'" & sVal & "'">
							<CFSET isFirst = "N">
						<CFELSE>
							<CFSET sFields = sFields & "," & COLUMNNAME>
							<CFSET sValues = sValues & ",'" & sVal & "'">
						</CFIF>
					</CFLOOP>
					<CFSET sFields = sFields & ",APPROVED,ROUTEID">
					<CFSET sValues = sValues & ",'S','" & sRouteid & "'">
					<CFQUERY NAME="insert2tbl" DATASOURCE="#DSN#">
						INSERT INTO #GetData.TABLENAME_FK# (#sFields#)
						VALUES (#preserveSingleQuotes(sValues)#)
					</CFQUERY>
					<!--- insert to CRGROUTEMAIN --->
					<CFQUERY NAME = "qryGetUSERID" DATASOURCE = "#client.global_dsn#">
						SELECT A.USERID, A.PROFILENAME, B.LASTNAME, B.FIRSTNAME, B.MIDDLENAME FROM EGRGUSERMASTER A, #client.company_dsn#..CMFPA B
						WHERE A.GUID = B.GUID AND 
						<CFIF GetData.ISBADGE EQ "N">B.PERSONNELIDNO = '#PERSONNELIDNO#'<CFELSE>B.PERSONNELBADGENO = '#PERSONNELIDNO#'</CFIF>
					</CFQUERY>
					<CFSET sRouteParam = "levelid=" & """#GetLevel.LEVELID#""" & "|subcompanycode=" & """" & client.subcompany_code & """">
					<CFTRY>
						<CFQUERY NAME="insert2main" DATASOURCE="#client.company_dsn#">
							INSERT INTO CRGROUTEMAIN (ROUTEID,DESCRIPTION,TABLENAME_FK,ORIGINATOR,PRIORITY,RECCREATEDBY,RECDATECREATED,USERID,DATELASTUPDATE,TIMELASTUPDATE,ROUTEPARAMS)
							VALUES
								('#sRouteid#',
								 '#GetData.DESCRIPTION#',	
								 '#GetData.TABLENAME_FK#',
								 '#qryGetUSERID.USERID#',
								 '2',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#TimeFormat(Now(),"HH:mm:ss")#',
								 '#sRouteParam#')
						</CFQUERY>
						<!--- get next recipient --->
						<CFQUERY NAME="qryNxtAppUser" DATASOURCE="#client.company_dsn#">
							SELECT *
							FROM CINFFACTIVITY
							WHERE
								(PROCESSCODE = '#GetData.PROCESSCODE#')
							ORDER BY ORDERID, DESCRIPTION
						</CFQUERY>
						<!--- map next recipient --->
						<CFIF LCASE(qryNxtAppUser.MAPPING) EQ "userrole">
							<!--- get unitcode to use --->
							<CFSET sUnitCode2Use=Trim(qryNxtAppUser.UNITCODE)>
							<CFIF sUnitCode2Use IS "">
								<CFSET sUnitCode2Use="PERSONNELIDNO">
							</CFIF>
							<!--- get intended recipients --->
							<CFQUERY NAME="GetRecipients" DATASOURCE="#client.global_dsn#">
								SELECT USERGRPMEMBERSIDX, GUID FROM EGRGROLEINDEX, EGRGUSERMASTER
								WHERE
									EGRGUSERMASTER.USERID = EGRGROLEINDEX.USERGRPMEMBERSIDX AND
									USERGRPID_FK = '#qryNxtAppUser.ROLECODE#';
							</CFQUERY>
							<CFIF GetRecipients.RecordCount EQ 1>
								<CFMODULE TEMPLATE="#client.common_path#cfm_getuser.cfm" USERID="#GetRecipients.USERGRPMEMBERSIDX#">
								<CFIF ISFOUND>
									<!--- get userid --->
									<CFQUERY NAME = "qryRecUSERID" DATASOURCE = "#client.global_dsn#">
										SELECT A.USERID FROM EGRGUSERMASTER A, #client.company_dsn#..CMFPA B
										WHERE A.GUID = B.GUID AND 
										B.PERSONNELIDNO = '#PERID#'
									</CFQUERY>
									<CFSET sIntentedRec = qryRecUSERID.USERID>
								</CFIF>
							<CFELSE>
								<!--- get userid --->
								<CFQUERY NAME = "qryCmfRoleUSERID" DATASOURCE = "#client.company_dsn#">
									SELECT USERID FROM ECINBATCHROUTEROLE
									WHERE BATCHID = '#getform.formcode#' AND DOCNUMBER = '#url.docnumber#'
								</CFQUERY>
								<CFIF qryCmfRoleUSERID.RECORDCOUNT>
									<CFSET sIntentedRec = qryCmfRoleUSERID.USERID>
								</CFIF>
							</CFIF>
						<CFELSEIF LCASE(qryNxtAppUser.MAPPING) EQ "superior">
							<!--- get superior code --->
							<CFQUERY NAME="GetCode" DATASOURCE="#client.company_dsn#">
								SELECT SUPERIORCODE, GUID, PERSONNELIDNO
								FROM CMFPA
								WHERE PERSONNELIDNO = (SELECT SUPERIORCODE FROM CMFPA WHERE #stheID# = '#PERSONNELIDNO#')
							</CFQUERY>
							<CFQUERY NAME="IsExists" DATASOURCE="#client.global_dsn#">
								SELECT USERID
								FROM EGRGUSERMASTER
								WHERE
									GUID = '#GetCode.GUID#'
							</CFQUERY>
							<CFIF IsExists.RecordCount>
								<CFSET sIntentedRec = IsExists.USERID>
							</CFIF>
						</CFIF>
						<CFQUERY NAME="qryRecProfile" DATASOURCE="#client.global_dsn#">
							SELECT USERID, PROFILENAME FROM EGRGUSERMASTER
							WHERE USERID = '#sIntentedRec#'
						</CFQUERY>
						<!--- insert to CRGROUTEDETAILS --->
						<CFSET sRecordID = CreateUUID()>
						<CFQUERY NAME="insert2routedtl" DATASOURCE="#client.company_dsn#">
							INSERT INTO CRGROUTEDETAILS (ROUTEID,ORDERID,CURRENTSEQUENCE,REROUTE,ROUTER,ROUTERREMARKS,STATUS,ACTIVITYID,RECCREATEDBY,RECDATECREATED,USERID,DATELASTUPDATE,TIMELASTUPDATE)
							VALUES
								('#sRouteid#',
								 '1',
								 '1',
								 '',
								 '#qryGetUSERID.USERID#',
								 '',
								 'STARTED',
								 'INITIALIZATION',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#TimeFormat(Now(),"HH:mm:ss")#')
						</CFQUERY>
						<!--- insert to CRGROUTERECORDS --->
						<CFQUERY NAME="insert2routerec" DATASOURCE="#client.company_dsn#">
							INSERT INTO CRGROUTERECORDS (USERID_FK,ROUTEDATE,ORIGINATOR,PROCESSCODE,ACTIVITYID,ROUTEID,ISNEW,ISHIDE,RECORDID,RECCREATEDBY,RECDATECREATED,USERID,DATELASTUPDATE,TIMELASTUPDATE,ROUTETIME)
							VALUES
								('#sIntentedRec#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#qryGetUSERID.USERID#',
								 '#GetData.PROCESSCODE#',
								 '#qryNxtAppUser.ACTIVITYID#',
								 '#sRouteid#',
								 'Y',
								 'N',
								 '#sRecordID#',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#client.userid#',
								 '#DateFormat(Now(),"mm/dd/yyyy")#',
								 '#TimeFormat(Now(),"HH:mm:ss")#',
								 '#TimeFormat(Now(),"HH:mm:ss")#')
						</CFQUERY>
						<!--- update ECINBATCHDTL, ECINBATCHEMPS, ECINBATCHAPPLY --->
						<CFQUERY NAME="updateDTL" DATASOURCE="#client.company_dsn#">
							UPDATE ECINBATCHDTL
							SET
								ROUTEID = '#sRouteid#',
								ISROUTED = 'Y',
								DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
								TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#',
								USERID = '#client.userid#'
							WHERE (BATCHID = '#getform.formcode#') AND (DOCNUMBER = '#url.docnumber#') AND (PERSONNELIDNO = '#PERSONNELIDNO#') AND (REFERENCEID = '#REFERENCEID#')
						</CFQUERY>
						<!--- COMMENT OUT : MAAN 02/19/2008 ROUTEID WILL SOON BE GONE
						<CFQUERY NAME="updateEMPS" DATASOURCE="#client.company_dsn#">
							UPDATE ECINBATCHEMPS
							SET
								ROUTEID = '#sRouteid#',
								DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
								TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#',
								USERID = '#client.userid#'
							WHERE (BATCHID = '#getform.formcode#') AND (DOCNUMBER = '#url.docnumber#') AND PERSONNELIDNO = '#PERSONNELIDNO#'
						</CFQUERY>--->
						<CFQUERY NAME="updateMaster" DATASOURCE="#client.company_dsn#">
							UPDATE ECINBATCHAPPLY
							SET
								ROUTED = 'Y',
								DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
								TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#',
								USERID = '#client.userid#'
							WHERE (BATCHID = '#getform.formcode#') AND (DOCNUMBER = '#url.docnumber#')
						</CFQUERY>
						<CFTRANSACTION ACTION="COMMIT"/>
						<CFCATCH TYPE="Database">
							<CFSET sWarn = "#CFCATCH.MESSAGE#" & "<BR>" & "#CFCATCH.DETAIL#">
							<CFTRANSACTION ACTION="ROLLBACK"/>
						</CFCATCH>
					</CFTRY>
					<!--- relocated: MAAN 03/31/2008; will send route notification by group 
					<CFINCLUDE TEMPLATE="batchAppRouteNotify.cfm"> --->
				</CFIF>
			</CFLOOP>
			<!--- added by Maan 03/31/2008 for batch content --->
			<CFQUERY NAME="qryApprover2Notify" DATASOURCE="#client.company_dsn#">
				SELECT DISTINCT(USERID_FK) AS USERID_FK
				FROM CRGROUTERECORDS
				WHERE ROUTEID IN (SELECT DISTINCT(ROUTEID) FROM ECINBATCHDTL WHERE REFERENCEID IN (#QuotedValueList(qryRefID.REFERENCEID)#)) AND ISHIDE= 'N'
				ORDER BY USERID_FK
			</CFQUERY>
			<CFIF qryApprover2Notify.RECORDCOUNT>
				<CFLOOP QUERY="qryApprover2Notify">
					<CFQUERY NAME="qryNotifyProfile" DATASOURCE="#client.global_dsn#">
						SELECT USERID, PROFILENAME FROM EGRGUSERMASTER
						WHERE USERID = '#qryApprover2Notify.USERID_FK#'
					</CFQUERY>
					<CFINCLUDE TEMPLATE="batchAppRouteNotify.cfm">
				</CFLOOP>
			</CFIF>
			<CFIF sWarn EQ "">
				<CFSET sMess = "Record(s) successfully routed">
			<CFELSE>
				<CFSET sWarn = sWarn>
			</CFIF>
		</CFIF>
		<CFMODULE TEMPLATE="#client.common_path#cfm_geturlvariables.cfm" REMOVEURL="edit,DOCNUMBER">
		<CFLOCATION url="#getFileFromPath(getBaseTemplatePath())#?#urlVariables#&sMess=#sMess#&sWarn=#sWarn#&routed=">
	<CFELSE>
		<!--- get distinct records --->
		<CFQUERY NAME="qryReturnedID" DATASOURCE="#client.company_dsn#">
			SELECT DISTINCT(ROUTEID) AS ROUTEID, PERSONNELIDNO
			FROM ECINBATCHDTL
			WHERE 	
				(DOCNUMBER = '#url.docnumber#') AND 
				(ROUTEID IN 
					(SELECT ROUTEID FROM #GetData.TABLENAME_FK# 
						WHERE (APPROVED = 'R')
					))
		</CFQUERY>
		<CFIF qryReturnedID.RECORDCOUNT>
			<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLevel.LEVELID#">
			<CFLOOP QUERY = "qryReturnedID">
				<CFSET sValues = "">
				<!--- get equivalent record --->
				<CFQUERY NAME="qryBatchDtl" DATASOURCE="#client.company_dsn#">
					SELECT * FROM ECINBATCHDTL
					WHERE 	ROUTEID = '#ROUTEID#'
				</CFQUERY>
				<CFIF qryBatchDtl.RECORDCOUNT> <!--- proceed to routing ONLY if there is an existing record -- maan 02/20/2008 --->
				<!--- update respective tables --->
					<CFLOOP QUERY="qryBatchDtl">
						<CFSET sValues = sValues & COLUMNNAME & "='" & FIELDVALUE & "',">
					</CFLOOP>
					<CFSET sValues = sValues & "APPROVED='S'">
					<CFQUERY NAME="updateTbl" DATASOURCE="#DSN#">
						UPDATE #GetData.TABLENAME_FK# SET #preserveSingleQuotes(sValues)#
						WHERE ROUTEID = '#ROUTEID#'
					</CFQUERY>
					<CFQUERY NAME = "qryGetUSERID" DATASOURCE = "#client.global_dsn#">
						SELECT A.USERID, A.PROFILENAME, B.LASTNAME, B.FIRSTNAME, B.MIDDLENAME FROM EGRGUSERMASTER A, #client.company_dsn#..CMFPA B
						WHERE A.GUID = B.GUID AND 
						<CFIF GetData.ISBADGE EQ "N">B.PERSONNELIDNO = '#PERSONNELIDNO#'<CFELSE>B.PERSONNELBADGENO = '#PERSONNELIDNO#'</CFIF>
					</CFQUERY>
					<!--- get next recipient --->
					<CFQUERY NAME="qryNxtAppUser" DATASOURCE="#client.company_dsn#">
						SELECT *
						FROM CINFFACTIVITY
						WHERE
							(PROCESSCODE = '#GetData.PROCESSCODE#')
						ORDER BY ORDERID, DESCRIPTION
					</CFQUERY>
					<CFQUERY NAME="qryReRouteActID" DATASOURCE="#client.company_dsn#">
						SELECT *
						FROM CINFFACTIVITY
						WHERE
							(PROCESSCODE = '#GetData.PROCESSCODE#') AND ORDERID = 1
						ORDER BY ORDERID, DESCRIPTION
					</CFQUERY>
					<!--- map next recipient --->
					<CFIF LCASE(qryNxtAppUser.MAPPING) EQ "userrole">
						<!--- get unitcode to use --->
						<CFSET sUnitCode2Use=Trim(qryNxtAppUser.UNITCODE)>
						<CFIF sUnitCode2Use IS "">
							<CFSET sUnitCode2Use="PERSONNELIDNO">
						</CFIF>
						<!--- get intended recipients --->
						<CFQUERY NAME="GetRecipients" DATASOURCE="#client.global_dsn#">
							SELECT USERGRPMEMBERSIDX, GUID FROM EGRGROLEINDEX, EGRGUSERMASTER
							WHERE
								EGRGUSERMASTER.USERID = EGRGROLEINDEX.USERGRPMEMBERSIDX AND
								USERGRPID_FK = '#qryNxtAppUser.ROLECODE#';
						</CFQUERY>
						<CFIF GetRecipients.RecordCount EQ 1>
							<CFMODULE TEMPLATE="#client.common_path#cfm_getuser.cfm" USERID="#GetRecipients.USERGRPMEMBERSIDX#">
							<CFIF ISFOUND>
								<!--- get userid --->
								<CFQUERY NAME = "qryRecUSERID" DATASOURCE = "#client.global_dsn#">
									SELECT A.USERID FROM EGRGUSERMASTER A, #client.company_dsn#..CMFPA B
									WHERE A.GUID = B.GUID AND 
									B.PERSONNELIDNO = '#PERID#'
								</CFQUERY>
								<CFSET sIntentedRec = qryRecUSERID.USERID>
							</CFIF>
						<CFELSE>
							<!--- get userid --->
							<CFQUERY NAME = "qryCmfRoleUSERID" DATASOURCE = "#client.company_dsn#">
								SELECT USERID FROM ECINBATCHROUTEROLE
								WHERE BATCHID = '#getform.formcode#' AND DOCNUMBER = '#url.docnumber#'
							</CFQUERY>
							<CFIF qryCmfRoleUSERID.RECORDCOUNT>
								<CFSET sIntentedRec = qryCmfRoleUSERID.USERID>
							</CFIF>
						</CFIF>
					<CFELSEIF LCASE(qryNxtAppUser.MAPPING) EQ "superior">
						<!--- get superior code --->
						<CFQUERY NAME="GetCode" DATASOURCE="#client.company_dsn#">
							SELECT SUPERIORCODE, GUID, PERSONNELIDNO
							FROM CMFPA
							WHERE PERSONNELIDNO = (SELECT SUPERIORCODE FROM CMFPA WHERE #stheID# = '#PERSONNELIDNO#')
						</CFQUERY>
						<CFQUERY NAME="IsExists" DATASOURCE="#client.global_dsn#">
							SELECT USERID
							FROM EGRGUSERMASTER
							WHERE
								GUID = '#GetCode.GUID#'
						</CFQUERY>
						<CFIF IsExists.RecordCount>
							<CFSET sIntentedRec = IsExists.USERID>
						</CFIF>
					</CFIF>
					<CFQUERY NAME="qryRecProfile" DATASOURCE="#client.global_dsn#">
						SELECT USERID, PROFILENAME FROM EGRGUSERMASTER
						WHERE USERID = '#sIntentedRec#'
					</CFQUERY>
					<CFQUERY NAME="qryMaxSeq" DATASOURCE="#client.company_dsn#">
						SELECT MAX(CURRENTSEQUENCE) AS CURRENTSEQUENCE FROM CRGROUTEDETAILS
						WHERE ROUTEID = '#ROUTEID#'
					</CFQUERY>
					<!--- insert to CRGROUTEDETAILS --->
					<CFQUERY NAME="updateRoutedtl" DATASOURCE="#client.company_dsn#">
						INSERT INTO CRGROUTEDETAILS
							(ROUTEID, ORDERID, CURRENTSEQUENCE, ROUTER, ROUTERREMARKS, STATUS, ACTIVITYID,
							RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE)
						VALUES
							('#ROUTEID#', 1, '#qryMaxSeq.CURRENTSEQUENCE + 1#', '#qryGetUSERID.USERID#', '', 'RE-ROUTE', '#qryReRouteActID.ACTIVITYID#',
							'#client.userid#',
							'#DateFormat(Now(),"mm/dd/yyyy")#',
							'#client.userid#',
							'#DateFormat(Now(),"mm/dd/yyyy")#',
							'#TimeFormat(Now(),"HH:mm:ss")#')
					</CFQUERY>
					<!--- update CRGROUTERECORDS -- worklist of application --->
					<CFQUERY NAME="updateRouterec" DATASOURCE="#client.company_dsn#">
						UPDATE CRGROUTERECORDS
						SET	ISHIDE = 'Y',
							USERID = '#client.userid#',
							DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
							TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#'
						WHERE ROUTEID = '#ROUTEID#' AND USERID_FK = '#qryGetUSERID.USERID#'
					</CFQUERY>
					<!--- update CRGROUTERECORDS --->
					<CFQUERY NAME="updateRouterec" DATASOURCE="#client.company_dsn#">
						UPDATE CRGROUTERECORDS
						SET	ISHIDE = 'N',
							ISNEW= 'Y',
							USERID = '#client.userid#',
							DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
							TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#'
						WHERE ROUTEID = '#ROUTEID#' AND USERID_FK = '#sIntentedRec#'
					</CFQUERY>
					
					<!--- update ECINBATCHDTL --->
					<CFQUERY NAME="updateDTL" DATASOURCE="#client.company_dsn#">
						UPDATE ECINBATCHDTL
						SET
							ISROUTED = 'Y',
							DATELASTUPDATE = '#DateFormat(Now(),"mm/dd/yyyy")#',
							TIMELASTUPDATE = '#TimeFormat(Now(),"HH:mm:ss")#',
							USERID = '#client.userid#'
						WHERE ROUTEID = '#ROUTEID#'
					</CFQUERY>
					<!---
					<CFTRANSACTION ACTION="COMMIT"/>
					<CFCATCH TYPE="Database">
						<CFSET sWarn = "#CFCATCH.MESSAGE#" & "<BR>" & "#CFCATCH.DETAIL#">
						<CFTRANSACTION ACTION="ROLLBACK"/>
					</CFCATCH>
					</CFTRY>
					---->
					<!--- Get sRecordID --->
					<CFQUERY NAME="qrysRecordID" DATASOURCE="#client.company_dsn#">
						SELECT RECORDID FROM CRGROUTERECORDS
						WHERE ROUTEID = '#ROUTEID#'
					</CFQUERY>
					<CFSET sRecordID = qrysRecordID.RECORDID>
					<!--- relocated: MAAN 03/31/2008; will send route notification by group
					<CFINCLUDE TEMPLATE="batchAppRouteNotify.cfm">--->
				</CFIF>
			</CFLOOP>
			<!--- added by Maan 03/31/2008 for batch content --->
			<CFQUERY NAME="qryApprover2Notify" DATASOURCE="#client.company_dsn#">
				SELECT DISTINCT(USERID_FK) AS USERID_FK
				FROM CRGROUTERECORDS
				WHERE ROUTEID IN (#QuotedValueList(qryReturnedID.ROUTEID)#) AND ISHIDE= 'N'
				ORDER BY USERID_FK
			</CFQUERY>
			<CFIF qryApprover2Notify.RECORDCOUNT>
				<CFLOOP QUERY="qryApprover2Notify">
					<CFQUERY NAME="qryNotifyProfile" DATASOURCE="#client.global_dsn#">
						SELECT USERID, PROFILENAME FROM EGRGUSERMASTER
						WHERE USERID = '#qryApprover2Notify.USERID_FK#'
					</CFQUERY>
					<CFINCLUDE TEMPLATE="batchAppRouteNotify.cfm">
				</CFLOOP>
			</CFIF>
			<CFIF sWarn EQ "">
				<CFSET sMess = "Record(s) successfully routed">
			<CFELSE>
				<CFSET sWarn = sWarn>
			</CFIF>
		</CFIF>
		<CFMODULE TEMPLATE="#client.common_path#cfm_geturlvariables.cfm" REMOVEURL="edit,DOCNUMBER">
		<CFLOCATION url="#getFileFromPath(getBaseTemplatePath())#?#urlVariables#&sMess=#sMess#&sWarn=#sWarn#&routed=">
	</CFIF>
<CFELSE>
	<CFINCLUDE TEMPLATE="batchAppFlow.cfm">
</CFIF>
